package com.michaelbulava.TFS.ui.wizards.share;

import com.intellij.ide.wizard.CommitStepException;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import com.michaelbulava.TFS.Messages;
import com.michaelbulava.TFS.ui.framework.wizard.ExtendedWizardStep;
import com.michaelbulava.TFS.ui.wizards.common.IConnectWizard;
import com.michaelbulava.TFS.ui.wizards.common.IShareWizard;

import javax.swing.*;
import java.awt.*;
import java.text.MessageFormat;

/**
 * Created by MichaelA on 7/29/2015.
 */
public class ShareProjectSummaryWizardStep extends ExtendedWizardStep {
    public static final Object STEP_ID = new Object();
    private final IShareWizard wizard;

    private SummaryControl control;

    public ShareProjectSummaryWizardStep(IShareWizard wizard){
        super(Messages.getString("ShareProjectSummaryWizardStep.Title"));
        this.wizard = wizard;
    }

    @Override
    public void _init(){
        super._init();
        if (control == null)
            getComponent();
        control.projectNameLabel.setText(wizard.getProject().getName());
        control.localPathLabel.setText(wizard.getProject().getBasePath());
        control.serverPathLabel.setText(wizard.getProjectShareLocation());
        control.workpaceLabel.setText(wizard.getWorkspace().getName());
    }

    @Override
    public Object getStepId() {
        return STEP_ID;
    }

    @Override
    public Object getNextStepId() {
        return wizard.getNextStepId(this);
    }

    @Override
    public Object getPreviousStepId() {
        return wizard.getPreviousStepId(this);
    }

    @Override
    public void commit(CommitType commitType) throws CommitStepException {

    }

    @Override
    public boolean isComplete() {
        return true;
    }

    @Override
    public JComponent getComponent() {
        if (control == null)
            control = new SummaryControl();
        return control;
    }

    @Override
    public JComponent getPreferredFocusedComponent() {
        return null;
    }

    private class SummaryControl extends JPanel{
        private JLabel projectNameLabel;
        private JLabel localPathLabel;
        private JLabel serverPathLabel;
        private JLabel workpaceLabel;

        public SummaryControl(){
            super();

            setLayout(new GridLayoutManager(3, 1, new Insets(4, 4, 4, 4), -1, -1));

            final JPanel panel1 = new JPanel();
            panel1.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
            add(panel1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0,
                    false));

            final JTextPane textPane1 = new JTextPane();
            textPane1.setText(MessageFormat.format(Messages.getString("ShareProjectSummaryWizardStep.AddExplanationFormat"),
                    new Object[]{ wizard.getProject().getName() }) +
                    Messages.getString("ShareProjectSummaryWizardStep.NeedToCheckin"));
            panel1.add(textPane1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER,
                    GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_WANT_GROW,
                    GridConstraints.SIZEPOLICY_WANT_GROW, null, new Dimension(150, 50), null, 0, false));

            final Spacer spacer1 = new Spacer();
            add(spacer1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL,
                    1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));

            final JPanel panel2 = new JPanel();
            panel2.setLayout(new GridLayoutManager(5, 2, new Insets(0, 0, 0, 0), -1, -1));
            add(panel2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW,
                    GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0,
                    false));

            final JLabel label1 = new JLabel();
            label1.setText(Messages.getString("ShareProjectSummaryWizardStep.ProjectNameLabelText"));
            panel2.add(label1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));

            final JLabel label2 = new JLabel();
            label2.setText(Messages.getString("ShareProjectSummaryWizardStep.LocalPathLabelText"));
            panel2.add(label2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));

            final JLabel label3 = new JLabel();
            label3.setText(Messages.getString("ShareProjectSummaryWizardStep.ServerPathLabelText"));
            panel2.add(label3, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
            final JLabel label4 = new JLabel();

            label4.setText(Messages.getString("ShareProjectSummaryWizardStep.WorkspaceLabelText"));
            panel2.add(label4, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE,
                    GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));

            final Spacer spacer2 = new Spacer();
            panel2.add(spacer2, new GridConstraints(4, 1, 1, 1, GridConstraints.ANCHOR_CENTER,
                    GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, 1, null, null, null, 0,
                    false));

            projectNameLabel = new JLabel();
            projectNameLabel.setText("%Project Name%");
            panel2.add(projectNameLabel, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST,
                    GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null,
                    null, null, 0, false));

            localPathLabel = new JLabel();
            localPathLabel.setText("%Local Path%");
            panel2.add(localPathLabel, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST,
                    GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null,
                    null, null, 0, false));

            serverPathLabel = new JLabel();
            serverPathLabel.setText("%Server Path%");
            panel2.add(serverPathLabel, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST,
                    GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null,
                    null, null, 0, false));

            workpaceLabel = new JLabel();
            workpaceLabel.setText("%Workspace Name%");
            panel2.add(workpaceLabel, new GridConstraints(3, 1, 1, 1, GridConstraints.ANCHOR_WEST,
                    GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null,
                    null, null, 0, false));
        }
    }
}
